define(function(require, exports, module) {
	J = jQuery;
	require('bootstrap');
	require('bootstraponhover');
	require('handlebars');
	require('waterfall');
	require('masonry');
	require('waypoints');
	require('hideseek');
	require('layer');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	var timenow = new Date().getTime();
	
	//用户登录后鼠标经过菜单
	$(".right-part").bootstrapDropdownOnHover();
	$(".menu-bar").bootstrapDropdownOnHover();
	
	var id=$(".album_id").attr("data-id");
	$('#board_pins_waterfall').waterfall({
	    itemCls: 'layer-view',
	    colWidth: 86,  
	    gutterWidth: 3,
	    gutterHeight: 3,
	    maxPage:5,
	    checkImagesLoaded: true,
	    callbacks: {
	        loadingFinished: function($loading, isBeyondMaxPage) {
	            if ( !isBeyondMaxPage ) {
	                $loading.fadeOut();
	            } else {
	                $loading.hide();
	                $('#board_pins_waterfall').show();
	            }
	        },
	        renderData: function (data, dataType) {
	            var tpl,
	                template,
	                resultNum = data.data.pageCount;
	            
	            if (data.data.pageNum > resultNum || resultNum > 20) {
	                $('#board_pins_waterfall').waterfall('pause', function() {
	                    $('.waterfall-loading').html('<p style="color:#666;">数据加载完毕...</p>')
	                });
	                //alert(resultNum); 
	                $('.waterfall-loading').hide();
	            }else{
		            if ( dataType === 'json' ||  dataType === 'jsonp'  ) { // json or jsonp format
		                tpl = $('#waterfall-tpl').html();
		                template = Handlebars.compile(tpl);
		    
		                return template(data);
		            } else { // html format
		                return data;
		            }
	            }
	    
	            
	        }
	    },
	    path: function(page) {
	        return '/album/pin_view.json?id='+id+'&p=' + page;
	    }
	});
	
	var cid=$(".waterfall").attr("data-id");
	$(".waterfall").waterfall({
		itemCls: 'pin', 
	    colWidth: 236,  
	    gutterWidth: 15,
	    gutterHeight: 15,
	    maxPage: 5,
	    bufferPixel: -50, 
	    auto_imgHeight:false,
	    align:'left',
	    resizable: true,
	    checkImagesLoaded: true,
	    callbacks: {
	        loadingFinished: function($loading, isBeyondMaxPage) {
	            if ( !isBeyondMaxPage ) {
	                $loading.fadeOut();
	            } else {
	                $loading.hide();
	                $('.waterfall').show();
	            }
	        },
	        renderData: function (data, dataType) {
	            var tpl,
	                template,
	                resultNum = data.data.count;
	            
	            if ( resultNum < 20) {
	                $('.waterfall').waterfall('pause', function() {
	                    $('.waterfall-loading').html('<p style="color:#666;">数据加载完毕...</p>')
	                });
	                //alert(resultNum); 
	                $('.waterfall-loading').hide();
	            }
	    
	            if ( dataType === 'json' ||  dataType === 'jsonp'  ) { // json or jsonp format
	                tpl = $('#waterfall-pin').html();
	                template = Handlebars.compile(tpl);
	    
	                return template(data);
	            } else { // html format
	                return data;
	            }
	        }
	    },
	    path: function(page) {
	        return '/category/type_view.json?id='+cid+'&p=' + page;
	    }
	});
	
	//加载登录弹窗
	function userlogin(){
		if($("body").find(".black-overlay #login_frame").length==0){
			$("#footer").after("<div class=\'black-overlay\'><div id=\'login_frame\' class=\'\' style=\'margin-top: -215px;\'><img src=\'/assets/images/v2/logo.svg\' width=\'106\' height=\'36\' data-baiduimageplus-ignore=\'1\' class=\'logo\'><div class=\'sign-up\' style=\'display: none;\'><div class=\'holder\'><div class=\'with-line\'>用第三方帐号注册恋衣</div><div class=\'buttons\'><a href=\'/oauth/weibo/instant_login/?_ref=frame\' title=\'微博帐号登录\' rel=\'nofollow\' class=\'weibo\'></a><a href=\'/oauth/qzone/instant_login/?_ref=frame\' title=\'QQ帐号登录\' rel=\'nofollow\' class=\'qzone\'></a><a href=\'/oauth/wechat/instant_login/?_ref=frame\' title=\'微信帐号登录\' rel=\'nofollow\' class=\'wechat\'></a><a href=\'/oauth/douban/instant_login/?_ref=frame\' title=\'豆瓣帐号登录\' rel=\'nofollow\' class=\'douban\'></a></div><a class=\'switch-email-signup brown-link\'>使用手机号/邮箱注册</a></div><div class=\'switch\'>已有帐号？<a class=\'brown-link\'>登录到流行恋衣</a></div></div><div style=\'display: block;\' class=\'login\'><div class=\'holder\'><div class=\'with-line\'>使用第三方帐号登录</div><div class=\'buttons small\'><a href=\'/oauth/weibo/instant_login/?_ref=frame\' title=\'微博帐号登录\' rel=\'nofollow\' class=\'weibo\'></a><a href=\'/oauth/qzone/instant_login/?_ref=frame\' title=\'QQ帐号登录\' rel=\'nofollow\' class=\'qzone\'></a><a href=\'/oauth/wechat/instant_login/?_ref=frame\' title=\'微信帐号登录\' rel=\'nofollow\' class=\'wechat\'></a><a href=\'/oauth/douban/instant_login/?_ref=frame\' title=\'豆瓣帐号登录\' rel=\'nofollow\' class=\'douban\'></a><a href=\'/oauth/renren/instant_login/?_ref=frame\' title=\'人人帐号登录\' rel=\'nofollow\' style=\'margin-right: 0\' class=\'renren\'></a></div><div class=\'with-line\'>使用手机号/邮箱登录</div><form action=\'/auth/\' method=\'post\' class=\'mail-login\'><input type=\'hidden\' name=\'_ref\' value=\'frame\'><input type=\'text\' name=\'email\' placeholder=\'输入手机号或者邮箱\' class=\'clear-input\'><input name=\'password\' type=\'password\' placeholder=\'密码\' class=\'clear-input\'><a href=\'#\' onclick=\'return false;\' class=\'btn btn18 rbtn\'><span class=\'text\'> 登录</span></a></form><a class=\'reset-password red-link\'>忘记密码»</a><div class=\'switch-back\'>还没有恋衣帐号？<a id=\'login-link\' class=\'red-link\'>点击注册»</a></div></div></div><div style=\'display: none\' class=\'reset\'><div class=\'holder\'><div class=\'with-line\'>找回密码</div><form class=\'reset-form\'><input type=\'text\' name=\'email\' placeholder=\'输入手机号或者邮箱\' class=\'clear-input\'><a href=\'#\' onclick=\'return false;\' class=\'btn btn18 rbtn\'><span class=\'text\'> 重置</span></a></form><a class=\'back red-link\'>又想起来了»</a></div></div><div class=\'email-signup\'><div style=\'display: none\' class=\'signup-success\'><div class=\'with-line\'>注册成功</div><div class=\'text\'>验证邮件已经发送到<span class=\'email\'>email</span>，请<a href=\'\' target=\'_blank\' class=\'check-mail red-link\'>点击查收邮件</a>激活账号。<br>没有收到激活邮件？请耐心等待，或者<a class=\'resend red-link disabled\'>重新发送<span>30</span></a></div><a class=\'login-link red-link\'>« 返回登录页</a></div><div style=\'display: none\' class=\'signup-form\'><div class=\'holder\'><div class=\'with-line\'>使用手机号/邮箱注册</div><form action=\'\' method=\'post\'><input type=\'text\' name=\'email\' placeholder=\'输入手机号或者邮箱\' class=\'clear-input\'><div id=\'captcha\' class=\'captcha\'></div><a href=\'#\' onclick=\'return false;\' class=\'btn btn18 rbtn\'><span class=\'text\'> 注册</span></a></form><a class=\'email-signup-back brown-link\'>« 返回第三方帐号登录</a></div></div></div><div class=\'close\'><i></i></div></div></div>");
		}
	}
	
	//关闭弹出的登录窗口---删除加载元素
	$(document).on('click', '.close', function (){
		$(this).parent().parent().remove();
	});
	
	//切换到注册页面
	$(document).on('click', '#login-link', function (){
		$(this).parent().parent().parent().parent().addClass('switching');
		setTimeout(function() { $("#login_frame").removeClass('switching'); }, 800); 
		$(this).parent().parent().parent().parent().removeAttr("style");
		$(this).parent().parent().parent().css("display","none");
		$(this).parent().parent().parent().prev().css("display","block");
	});
	
	//切换到登录页面
	$(document).on('click', '.brown-link', function (){
		$(this).parent().parent().parent().addClass('switching');
		setTimeout(function() { $("#login_frame").removeClass('switching'); }, 800); 
		$(this).parent().parent().parent().parent().removeAttr("style");
		$(this).parent().parent().parent().css("margin-top","-215px");
		$(this).parent().parent().css("display","none");
		$(this).parent().parent().next().css("display","block");
	});
	
	//切换到找回密码页面
	$(document).on('click', '.reset-password', function (){
		$(this).parent().parent().parent().addClass('switching');
		setTimeout(function() { $("#login_frame").removeClass('switching'); }, 800); 
		$(this).parent().parent().parent().css("margin-top","-137px");
		$(this).parent().parent().parent().css("height","214px");
		$("#login_frame .login").css("display","none");
		$("#login_frame .reset").css("display","block");
	});
	
	//找回密码页面切换到登录页面
	$(document).on('click', '.holder .back', function (){
		$(this).parent().parent().parent().addClass('switching');
		setTimeout(function() { $("#login_frame").removeClass('switching'); }, 800); 
		$(this).parent().parent().parent().removeAttr("style");
		$(this).parent().parent().parent().css("margin-top","-215px");
		$("#login_frame .sign-up").css("display","none");
		$("#login_frame .login").css("display","block");
		$(this).parent().parent().css("display","none");
	});
	
	//回复评论
	$(document).on('click', '.reply-button', function (){
		var uname=$(this).attr("data-name");
		var uid=$(this).attr("data-id");
		$(".clear-input").attr('placeholder','回复'+uname+'：').focus();
		$("#touid").val(uid);
	});
	
	//内容页评论提交表单显示
	$(document).on('focus', '.clear-input', function (){
		$(".review-btn").show();
	});	
	
	//检测字符数是否允许提交
	$(document).on('keyup', '.clear-input', function (){
		var comment=$(".clear-input").val().length;
		if(comment>=2){
			$(".review-btn").removeClass('disabled');
		}else{
			$(".review-btn").addClass('disabled');
		}
	});
	
	//用户添加评论
	$(".review-btn").on("click", function(){
		var id=$("#pin_view_add_comment").attr("data-id");
		var content=$(".clear-input").val();
		var touid=$("#touid").val();
		$.ajax({
    		url: '/member/addComment.json', 
    		data: {'id': id,'content': content,'touid': touid},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(data){	
    			if(data.code==0){
    				//弹出提示5秒后刷新页面
    				layer.msg(data.message,{icon:1,time:5000},function(){
    	                //window.location.href = "/member/login";
    	            });
    				$("#touid").val("");
    				$(".clear-input").attr('placeholder','添加评论或把最新时装@给好友').focus();
    				$(".clear-input").val("");
    				$.get("/comment/img_review.json", { id: id }, function(data){
    					$(".comments").html("");
    					if(data.data.list!=null){
    						$.each(data.data.list, function(k, v) {
    							var review="";
    							if(v.toUid!=null){
    								review="<span>回复   <a href=\"/u/"+v.toUid+"/\" class=\"author\">"+v.toNickname+"</a>： </span>";
    							}
    							$(".comments").append("<div data-id=\'"+v.commentId+"\' class=\'comment\'><a href=\'/u/"+v.userId+"/\' title=\'"+v.nickname+"\' class=\'img x\'><img src=\'"+v.face+"\' class=\'avatar\'></a><div class=\'meta\'><a href=\'/u/"+v.userId+"/\' class=\'author\'>"+v.nickname+"</a>&nbsp;-&nbsp;<span data-ts=\'"+v.userId+"\' class=\'ts-words\'> "+v.addtime+"</span>说：</div><div class=\'text\'>"+review+v.content+"</div><div class=\'action-buttons\'><a data-name=\'"+v.nickname+"\' title=\'回复\' class=\'reply-button\'></a><a title=\'举报\' class=\'report-button\'></a></div></div>");
    						});
    					}
    				});	
    				return false;
    			}else{
    				layer.msg(data.message, {icon: 2});
				}
          	}
    	});
	});
	
	//加载之前评论内容
	var p=2;
	$(document).on('click', '.more-comments', function (){
		var id=$("#pin_view_add_comment").attr("data-id");
		$.get("/comment/img_review.json", { id: id ,p: p}, function(data){
			if((data.data.pageCount+1)>=p){
				if(data.data.list!=null){
					$.each(data.data.list, function(k, v) {
						var review="";
						if(v.to_uid!=null){
							review="<span>回复   <a href=\"/u/"+v.to_uid+"/\" class=\"author\">"+v.to_nickname+"</a>： </span>";
						}
						$(".comments").prepend("<div data-id=\'"+v.commentId+"\' class=\'comment\'><a href=\'/u/"+v.userId+"/\' title=\'"+v.nickname+"\' class=\'img x\'><img src=\'"+v.face+"\' class=\'avatar\'></a><div class=\'meta\'><a href=\'/u/"+v.userId+"/\' class=\'author\'>"+v.nickname+"</a>&nbsp;-&nbsp;<span data-ts=\'"+v.userId+"\' class=\'ts-words\'> "+v.addtime+"</span>说：</div><div class=\'text\'>"+review+v.content+"</div><div class=\'action-buttons\'><a data-name=\'"+v.nickname+"\' title=\'回复\' class=\'reply-button\'></a><a title=\'举报\' class=\'report-button\'></a></div></div>");
					});
				}
				if((data.data.pageCount+1)==p){
					$(".more-comments").hide();
				}
			}
		});
		p=p+1;
	});
	
	//瀑布流评论点击下拉
	$(document).on('click', '.replyButton', function (){
		if(userid==null || userid==""){
			userlogin();
			return false;
		}
		var pinbox=$(this).parent().parent().parent().parent();
		var leftnum=$(this).parent().parent().parent().parent().position().left;

		$.each(pinbox.nextAll(), function(){
			if ($(this).css("left") == leftnum+"px") { 
				if(pinbox.find("#addcomment").length==0){
					var topnum=$(this).position().top;
				    $(this).css('top',(topnum+108)+'px');
				}
			}
		});
		if(pinbox.find("#addcomment").length==0){
		    pinbox.find(".comments").after("<div id=\'addcomment\' class=\'write convo clearfix\'><a href=\'#\' title=\'\' class=\'img x\'><img src=\'"+smallAvatar+"\'></a><textarea placeholder=\'添加评论或把采集@给好友\' class=\'clear-input GridComment\'></textarea><a href=\'#\' onclick=\'return false;\' class=\'grid_comment_button btn\' style=\'display: block;\'><span class=\'text\'> 添加评论</span></a></div>");
		}
		$.each($('.waterfall .pin'), function(){
			var p1Bottom = $('.waterfall').offset().top+$('.waterfall').height(),
			p2Bottom = $(this).offset().top+$(this).height();
			if(p2Bottom>p1Bottom){
				pinbox.parent().css('height',(p2Bottom-p1Bottom+$('.waterfall').height()+20)+'px');
			}
		});
	});
	
	$(document).on('focus', '.GridComment', function (){
		var pinbox=$(this).parent().parent();
		$($(this).parent().parent().siblings()).each(function() { 
			if($(this).children().children(".grid_comment_button").css("display")=="block"){
				var leftcomment=$(this).position().left;
					$.each($(this).nextAll(), function(){
						if ($(this).css("left") == leftcomment+"px") {
				            var topnum=$(this).position().top;
							$(this).css('top',(topnum-40)+'px');
						}
					});
				$(this).children().children(".grid_comment_button").hide();
            }
        });

		var leftnum=$(this).parent().parent().position().left;
		$.each($(this).parent().parent().nextAll(), function(){
			if ($(this).css("left") == leftnum+"px") { 
				if(pinbox.children().children(".grid_comment_button").css("display")=="none"){
					var topnum=$(this).position().top;
				    $(this).css('top',(topnum+40)+'px');
				}
			}
		});
		$(this).next(".grid_comment_button").show();
	});
	
	
	$(".follow-btn").on("click", function(){
		var uid=$(this).attr("data-id");
		$.ajax({
    		url: '/u/userfollow.json?'+timenow, 
    		data: {'userByid': uid},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				$(this).children(".text").html("已关注");
    				layer.msg(data.message, {icon: 1});
    			}else{
    				$(this).children(".text").html("关注");
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
	});
	
	//添加专辑弹窗
	$(document).on('click', '.repin', function (){
		var id=$(this).attr("data-id");
		$.get("/pin/pin_view.json", { id: id },
		    function(data){
			result=data.data.imgurl;
			if ( $("#repin_dialog").length < 1 ) { 
				var imgdesc=data.data.imgdesc;
				if(imgdesc==null || imgdesc==""){
					imgdesc="";
				}
				$(".dialog-boxes").append("<div class=\"dialog-overlay\"></div><div id=\"repin_dialog\" data-name=\"repin\" class=\"dialog-box\"><div class=\"box-title\">收藏</div><div class=\"box-inner\"><div id=\"uniq_498927\" class=\"pin-create\"><div class=\"preview\" style=\"padding-top: 70px;\"><div class=\"image\"><img src=\""+data.data.imgurl+"\" id=\"imgurl\"></div><textarea placeholder=\"点击添加描述...\" class=\"description\">"+imgdesc+"</textarea></div><div class=\"right-part\" id=\"album-list\"><input id=\"search-nodata\" class=\"clear-input search-input\" name=\"search-nodata\" placeholder=\"搜索或创建专辑\" type=\"text\" data-list=\".nodata_list\" autocomplete=\"off\"><div style=\"display: none; margin-bottom: 10px;\" class=\"common-message info\"></div><div class=\"board-divider\"></div><div class=\"boardlist\"><div class=\"scrollable\"><ul class=\"vertical nodata_list\"></lu><div class=\"sorted\"></div><div class=\"sorted\"></div></div></div><div class=\"text-block-divider\"></div><div class=\'text-block\'><div style=\'display: none;\' class=\'createboard\'><i class=\'icon add\'></i>创建画板 “<span class=\'text\'></span>”</div><div class=\'tag-inputs\'><input placeholder=\'输入文字，按空格或回车以生成标签\' class=\'clear-input taginput\' style=\'display: none;\'><div class=\'tag-input\'><div class=\'tag-labels\'></div><input class=\'clear-input taginput\'><div class=\'placeholder\' style=\'display: block;\'>输入文字，按空格或回车以生成标签</div></div></div><div class=\'tag-bar\'><div style=\'display: block;\' class=\'normal\'><span class=\'title\'>推荐标签</span><span class=\'tags\'><div class=\'tag\'>妩媚</div><div class=\'tag\'>小清新</div><div class=\'tag\'>可爱</div><div class=\'tag\'>齐刘海</div><div class=\'tag\'>模特</div><div class=\'tag\'>诱惑</div></span></div></div></div><div class=\"text-block\"><div style=\"display: none;\" class=\"createboard\"><i class=\"icon add\"></i>创建专辑 “<span class=\"text\"></span>”</div></div></div><div class=\"bottom-part\"><input id=\"add_pin_id\" name=\"pin_id\" value=\""+id+"\" type=\"hidden\"><input id=\"add_album_id\" name=\"album_id\" value=\"\" type=\"hidden\"><div class=\"buttons\"><a href=\"#\" onclick=\"return false;\" class=\"addpin btn btn18 rbtn \"><span class=\"text\"> 确认收藏</span></a></div></div></div></div><div class=\"close-btn\"><i></i></div></div>");
			}else{
				$(".dialog-overlay").show();
				$("#repin_dialog").show();
				$("#imgurl").attr("src",data.data.imgurl);
				$("#add_pin_id").val(id);
			};
			$(".vertical").html("");
			if(data.data.albumlist!=null){
				$.each(data.data.albumlist, function(k, v) {
					$(".vertical").append("<li class=\"item\" style=\"display: list-item;\" data-id=\""+v.albumId+"\">"+v.albumname+"<div class=\"controller\"></div></li>");
				});
			}
			$('#search-nodata').hideseek({
			    nodata: '没有查询到相关专辑可点击下面添加'
			});
			$($(".vertical").children("li").get(0)).addClass("selected");
			$("#add_album_id").val($($(".vertical").children("li").get(0)).attr("data-id"));
			$($(".vertical").children("li").get(0)).prepend("<i class=\"icon history\"></i>");
		});
	});
	
	//确定选择专辑
	$(document).on('click', '.item', function (){
		$(".item").removeClass("selected");
		$(this).addClass("selected");
		$("#add_album_id").val($(this).attr("data-id"));
	});
	
	//隐藏添加专辑弹窗
	$(document).on('click', '.close-btn', function (){
		$(".dialog-overlay").hide();
		$("#repin_dialog").hide();
	});
	
	//查询是否有该专辑
	$(document).on('keyup', '#search-nodata', function (){
		var text=$("#search-nodata").val();
		if($(".item:contains('"+text+"')").length==0){
			$(".createboard").show();
			$(".createboard > .text").html($.trim(text));
			console.log("无该关键词");
		}else{
			$(".createboard").hide();
		}
	});
	
	//弹窗位置添加专辑
	$(document).on('click', '.createboard', function (){
		var text=$("#search-nodata").val();
		$.ajax({
    		url: '/member/album/add.json?'+timenow, 
    		data: {'albumname': $.trim(text)},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				layer.msg(data.message, {icon: 1});
    				$(".vertical").append("<li class=\"item\" style=\"display: list-item;\" data-id=\""+data.data.album_id+"\">"+data.data.albumname+"<div class=\"controller\"></div></li>");
    				$(".createboard").hide();
    				$(".createboard > .text").html("");
    				$(".no-results").remove();
    				$("#add_album_id").val("");
    			}else{
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
	});
	
	//图集添加进用户专辑
	$(document).on('click', '.addpin', function (){
		var albumId=$("#add_album_id").val();
		var pinId=$("#add_pin_id").val();
		if(albumId==null||albumId==""){
			layer.msg('请点选专辑后再收藏！', {icon: 2});
			return false;
		}
		$.ajax({
    		url: '/album/pins.json?'+timenow, 
    		data: {'albumId': albumId,'pinId': pinId},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				layer.msg(data.message, {icon: 1});
    				$(".dialog-overlay").hide();
    				$("#repin_dialog").hide();
    			}else{
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
	});
	
	//图集添加进用户专辑
	$(document).on('click', '.like-btn', function (){
		var pinId=$(this).attr("data-id");
		if(pinId==null||pinId==""){
			layer.msg('图集id未获取到！', {icon: 2});
			return false;
		}
		$.ajax({
    		url: '/pin/addlove.json?'+timenow, 
    		data: {'pinId': pinId},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				var love=data.data.lovecount;
    				if($(".like-btn").is(".liked")){
						$(".like-btn").removeClass("liked");
					}else{
						$(".like-btn").addClass("liked");
					}
    				if(love > 0){
    					$(".like-btn").children().children(".num").html(data.data.lovecount);
    				}else{
    					$(".heart").parent().removeClass("liked");
    					$(".like-btn").children().children(".num").html("");
    				}
    			}else{
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
	});
	
	//添加用户关注的专辑
	$(document).on('click', '.follow-album', function (){
		var albumId=$(this).attr("data-id");
		if(albumId==null||albumId==""){
			layer.msg('请点选专辑后再收藏！', {icon: 2});
			return false;
		}
		$.ajax({
    		url: '/album/fans.json?'+timenow, 
    		data: {'albumId': albumId},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				if($(".follow-album").hasClass("unfollow")){
    					$(".follow-album").addClass("rbtn");
    					$(".follow-album").removeClass("unfollow");
    					$(".follow-album").children(".text").html("关注此专辑");
    					if(parseInt($(".tab").html().replace(/[^0-9]/ig,""))>0){
    						$(".tab").html("被"+(parseInt($(".tab").html().replace(/[^0-9]/ig,""))-1)+"人关注");
    					}
    				}else{
    					$(".follow-album").removeClass("rbtn");
    					$(".follow-album").addClass("unfollow");
    					$(".follow-album").children(".text").html("取消关注此专辑");
    					$(".tab").html("被"+(parseInt($(".tab").html().replace(/[^0-9]/ig,""))+1)+"人关注");
    				}
    			}else{
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
	});
});